package biz.login;

import utils.TransactionTemplate;
import models.Manager;
import models.Student;
import dao.ManagerDao;
import dao.ManagerDaoHbnImpl;
import dao.StudentDao;
import dao.StudentDaoHbnImpl;

public class LoginBizImpl implements LoginBiz {
	private StudentDao studentDao =new StudentDaoHbnImpl();
	private ManagerDao managerDao =new ManagerDaoHbnImpl();

	@Override
	public void addStudent(Student stu) {
		try {
			TransactionTemplate.beginTransaction();
			studentDao.addStudent(stu);
			TransactionTemplate.commit();
		} catch (Exception e) {
			e.printStackTrace();
			TransactionTemplate.rollback();
		}
	}

	@Override
	public Manager selManagerByNAP(String name, String password) {
		Manager mag=null;
		try {
			TransactionTemplate.beginTransaction();
			mag=managerDao.selManagerByNAP(name, password);
			TransactionTemplate.commit();
		} catch (Exception e) {
			e.printStackTrace();
			TransactionTemplate.rollback();
		}
		return mag;
	}

	@Override
	public Student selStudentByNAP(String name, String password) {
		Student stu=null;
		try {
			TransactionTemplate.beginTransaction();
			stu=studentDao.selStudentByNAP(name, password);
			TransactionTemplate.commit();
		} catch (Exception e) {
			e.printStackTrace();
			TransactionTemplate.rollback();
		}
		return stu;
	
	}

}
